var mask = null;
var refundid = null;
var xzauditstatus = null;
var bz = null;



$(function() { // 初始化内容
	mui.init();

		mask = mui.createMask(); //遮罩层
		
		login_user = JSON.parse(localStorage.getItem('loginUser'));
		refundid = sessionStorage.getItem('refundid')
		datetime_init();
		
		setTimeout(function() {
			loadRefundRecord();
		}, 300);
		

	

})



function loadRefundRecord() {
	
	var data = {};
	data['id'] = refundid;
	console.log("退款记录id===="+JSON.stringify(data));
	jQuery.ajax({
		headers: {
			'Authorization':  login_user.token
		},
		type: "post",
		url: serverip + "fxgw/loadtksp",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {
			
			mask.show(); //显示遮罩层
		},
		success: function(res) {
			mask.close(); //显示遮罩层
			console.log("退款记录===="+JSON.stringify(res));
			var onechannelname = res.newxlc_closing_record[0].onechannelname;
			var twochannelname = res.newxlc_closing_record[0].twochannelname;
			jQuery("#channal").val(onechannelname + "~" +twochannelname);
			loadForm(res.newxlc_closing_record[0]);
			var cashieraduitstatus =  res.newxlc_closing_record[0].cashieraduitstatus;
			var dqjlauditstatus = res.newxlc_closing_record[0].dqjlauditstatus;
			if(dqjlauditstatus != "审核中"){
				jQuery("#submit").css("display","none");
			}
			loadApp(res.adult_list)
		},
		error: function(e) {
		
			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码'+code+"\n"+"错误信息:"+msg);
			console.log("错误信息===="+JSON.stringify(e));
		
		}
	});

}



function pass(){
	xzauditstatus = "大区经理审核通过";
	noPassText()
}
function noPass(){
	xzauditstatus = "大区经理审核不通过";
	noPassText();
}

function saveAuditResult(){
	var data = {};
	if(bz != null){
		data['dqjlbz'] = bz;
	}
	data['id'] = refundid;
	data['auditposition'] = "大区经理";
	data['currentauditid'] = login_user.id;
	data['currentauditname'] = login_user.name;
	data['dqjlauditstatus'] = xzauditstatus;
	console.log("审核成交记录上传====" + JSON.stringify(data));
	jQuery.ajax({
	    type: "post",
		headers: {
            'Authorization': login_user.token
        },		    
	    url : serverip + "dqjl/tksp",
	    contentType: "application/json;charset=UTF-8",
	    data : JSON.stringify(data),
	    dataType: "json",
	    timeout: 10000,
	    beforeSend: function(){
	       
	        mask.show();//显示遮罩层	   
	    },	                
	    success: function(data) {
	    	
	        mask.close();//显示遮罩层  	    	
	    	console.log(JSON.stringify(data));
			mui.alert('审核完成');
			
			setTimeout(function() {
				mui.back();
			}, 1000);
	    },
	    
	    error: function(e) {

	       mask.close();//显示遮罩层
	       mui.alert('系统错误');
	       console.log("审核错误"+JSON.stringify(data));
	    }
	});	
}



function noPassText(){
	var btnArray = ['取消', '确定'];
	mui.prompt('请填写不通过原因','请填写不通过原因',new Array('取消','确定'),function(e){
	    if(e.index == 1){
	        //mui.toast(e.value);	    
	        bz = e.value;
	        saveAuditResult();

	    }else{
	        mui.toast('您取消了输入');
	    }
	});
}

var app = new Vue({
	el : '#teachertable',
	data : {
		show : true,
		todos : []
	},
	methods : {
		selected : function(todo) {			
				
		}
	}
});

function loadApp(data) {
	
	var arry = new Array();
	for(var i = 0; i < data.length; i++) {
		var d = data[i];
		var o = new Object();
		
	    for(var x in d){
     	  o[x] = d[x];
        }
		arry.push(o);
	}
	app.todos = arry;
	
}